package com.example.controller;

import com.example.pojo.Materials;
import com.example.pojo.PageBean;
import com.example.pojo.Result;
import com.example.service.MaterialService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/mater")
public class MaterialController {
    @Autowired
    private MaterialService materialService;
    @GetMapping
    public Result selectAll(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer pageSize,
                            String materialName, @RequestParam(defaultValue = "0") int stockQuantity){
        PageBean pageBean=materialService.page(page,pageSize,materialName,stockQuantity);
        return Result.success(pageBean);
    }
    @GetMapping("/sel")
    public Result getID(){
        List<Materials> materials = materialService.getIDs();
        return Result.success(materials);
    }
    @PostMapping
    public Result add(@RequestBody Materials materials){
        materialService.add(materials);
        return Result.success();
    }
    @PutMapping
    public Result updateAdd(@RequestBody Materials materials){
        materialService.addUpdate(materials);
        return Result.success();
    }

    @GetMapping("/cun")
    public Result update(String name,int num){
        materialService.update(name,num);
        return Result.success();
    }
    @DeleteMapping("/{ids}")
    public Result delete(@PathVariable List<Integer> ids){
        materialService.deletes(ids);
        return Result.success();
    }
    @GetMapping("/one")
    public Result getOne(String metrname){
        Materials materials=materialService.getOne(metrname);
        return Result.success(materials);
    }
}
